<template>
    <div>
        <div class="i-layout-page-header">
            <PageHeader class="product_tabs" :title="$route.meta.title" hidden-breadcrumb></PageHeader>
        </div>
        <Card :bordered="false" dis-hover class="ivu-mt">
            <div class="acea-row row-between-wrapper">
                <Row type="flex">
                    <Col v-bind="grid">
                        <div class="button acea-row row-middle">
                            <Button type="primary"  icon="md-add" @click="add">添加车辆</Button>
                        </div>
                    </Col>
                </Row>
                <!-- <Row type="flex">
                    <Col v-bind="grid">
                        <Button type="primary" @click="cleanCache">清除缓存</Button>
                    </Col>
                </Row> -->
            </div>
            <Table :columns="columns1" :data="dataLists" ref="table" class="mt25"
                   :loading="loading" highlight-row
                   no-userFrom-text="暂无数据"
                   no-filtered-userFrom-text="暂无筛选结果">

                 <template slot-scope="{ row, index }" slot="sex">
                    <div >{{row.sex==1?'男':'女'}}</div>
                </template>
                <template slot-scope="{ row, index }" slot="action">
                    <a @click="edit(row.id)">编辑</a>
                    <Divider type="vertical" />
                    <a @click="del(row,'删除车辆',index)">删除</a>
                </template>
            </Table>
            <div class="acea-row row-right page">
                <Page :total="total" :current="dataFrom.page" show-elevator show-total @on-change="pageChange"
                      :page-size="dataFrom.limit"/>
            </div>
        </Card>
    </div>
</template>

<script>
    import { mapState } from 'vuex';
    import { businessCarListApi, businessCarAddApi, businessCarEditApi, cityCleanCacheApi } from '@/api/setting';
    export default {
        name: "setting_dada",
        data() {
            return {
                grid: {
                    xl: 7,
                    lg: 7,
                    md: 12,
                    sm: 24,
                    xs: 24
                },
                loading: false,
                columns1: [
                    {
                        title: '编号',
                        key: 'id',
                        minWidth: 120
                    },
                    {
                        title: '车牌',
                        key: 'car_num',
                        minWidth: 300
                    },
                    {
                        title: '座位数',
                        key: 'seat',
                        minWidth: 300
                    },
                    {
                        title: '品牌',
                        key: 'brand',
                        minWidth: 300
                    },
                    {
                        title: '颜色',
                        key: 'color',
                        minWidth: 300
                    },
                    // {
                    //     title: '地区名称',
                    //     slot: 'region',
                    //     minWidth: 300
                    // },
                    {
                        title: '操作',
                        slot: 'action',
                        fixed: 'right',
                        minWidth: 120
                    },
                    
                ],
                dataLists: [],
                dataFrom: {
                    keyword: '',
                    page: 1,
                    limit: 20
                },
                total: 0,
                cityId:0//城市id
            }
        },
        computed: {
            ...mapState('admin/layout', [
                'isMobile'
            ]),
            labelWidth () {
                return this.isMobile ? undefined : 75;
            },
            labelPosition () {
                return this.isMobile ? 'top' : 'left';
            }
        },
        created () {
            this.getList();
        },
        methods:{
            //清除缓存；
            cleanCache () {
                cityCleanCacheApi ().then(res=>{
                    this.$Message.success(res.msg);
                }).catch(res=>{
                    this.$Message.success(res.msg);
                })
            },
            // 添加
            add () {
                this.$modalForm(businessCarAddApi()).then(() => this.getList());
            },
          
            pageChange (index) {
                this.dataFrom.page = index;
                this.getList();
            },
            // 列表
            getList () {
                let that = this;
                that.loading = true;
                businessCarListApi(this.dataFrom).then(async res => {
                    that.dataLists = res.data.list;
                      this.total = res.data.count;
                    that.loading = false;
                }).catch(res => {
                    that.loading = false;
                    console.log(1111,res)
                    that.$Message.error(res);
                })
            },
            //返回
            goBack(){
                this.getList();
            },
            //修改
            edit(id){
                this.$modalForm(businessCarEditApi(id)).then(() => this.getList());
            },
            // 删除
            del (row, tit, num) {
                let delfromData = {
                    title: tit,
                    num: num,
                    url: `setting/business_car/del/${row.id}`,
                    method: 'DELETE',
                    ids: ''
                };
                this.$modalSure(delfromData).then((res) => {
                    console.log(res);
                    this.$Message.success(res.msg);
                    this.dataLists.splice(num, 1);
                    this.getList();
                }).catch(res => {
                    this.$Message.error(res.msg);
                });
            },
        }
    }
</script>

<style scoped lang="stylus">
    .button
       width 300px;
</style>